<!-- eslint-disable -->
<template>
  <div>
    <el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" @close="dialogClose" width="550px" :close-on-click-modal="false">
      <el-form :model="form" ref="form" class="dialog-form" @submit.native.prevent>
        <el-form-item label="用户" :label-width="formLabelWidth"
          prop="user_id"
          :rules="[
            { required: false, message: '请输入用户', trigger: 'blur' }
          ]">
          <el-input size="medium" type="number" v-model="form.user_id"></el-input>
        </el-form-item>
        <el-form-item label="订单" :label-width="formLabelWidth"
          prop="orders_id"
          :rules="[
            { required: false, message: '请输入订单', trigger: 'blur' }
          ]">
          <el-input size="medium" type="number" v-model="form.orders_id"></el-input>
        </el-form-item>
        <el-form-item label="商品" :label-width="formLabelWidth"
          prop="goods_id"
          :rules="[
            { required: false, message: '请输入商品', trigger: 'blur' }
          ]">
          <el-input size="medium" type="number" v-model="form.goods_id"></el-input>
        </el-form-item>
        <el-form-item label="评论内容" :label-width="formLabelWidth"
          prop="content"
          :rules="[
            { required: false, message: '请输入评论内容', trigger: 'blur' }
          ]">
          <el-input size="medium" type="text" v-model="form.content"></el-input>
        </el-form-item>
        <el-form-item label="评分" :label-width="formLabelWidth"
          prop="score"
          :rules="[
            { required: false, message: '请输入评分', trigger: 'blur' }
          ]">
          <el-input size="medium" type="text" v-model="form.score"></el-input>
        </el-form-item>
        <el-form-item label="评论时间" :label-width="formLabelWidth"
          prop="created_at"
          :rules="[
            { required: false, message: '请选择评论时间', trigger: 'blur' }
          ]">
          <el-date-picker
            v-model="form.created_at"
            size="medium"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择评论时间">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="medium" @click="dialogFormVisible = false">取 消</el-button>
        <el-button size="medium" type="primary" @click="addData('form')" :loading="loadingAdd">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<!-- eslint-disable -->
<script>
  import {OrdersCommentAdd} from '@/utils/request.js'

  export default {
    components: {  },
    name: 'ordersCommentForm',
    data(){
      return {
        dialogTitle: '新增评论',
        dialogFormVisible: false,
        formLabelWidth: '100px',
        loadingAdd: false,
        form: {
          id: 0,
          user_id: '',
          orders_id: '',
          goods_id: '',
          content: '',
          score: '',
          created_at: '',
        },

      }
    },
    created() {

    },
    methods: {
      dialogClose() {
        this.initForm()
      },
      editTmp(row) {
        this.form = {
          id: row.id,
          user_id: row.user_id,
          orders_id: row.orders_id,
          goods_id: row.goods_id,
          content: row.content,
          score: row.score,
          created_at: row.created_at,
        }
        this.dialogTitle = this.form.id > 0 ? '编辑评论' : '新增评论'
        this.dialogFormVisible = true
      },
      addData(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.loadingAdd = true
            OrdersCommentAdd(this.form).then((res) => {
              if (res.code == 200) {
                this.$message.success(res.msg);
                this.$emit('refreshPage')
                this.dialogFormVisible = false
              } else {
                this.$message.error(res.msg);
              }
              this.loadingAdd = false
            })
          }
        });
      },
      initForm() {
        this.form = {
          id: 0,
          user_id: '',
          orders_id: '',
          goods_id: '',
          content: '',
          score: '',
          created_at: '',
        }
        this.$refs['form'].resetFields()
        this.dialogTitle = '新增评论'
      },

    }
  }
</script>

<style scoped>
  >>>.el-dialog__body {
    /* padding-right: 50px !important; */
    /* max-height: 500px; */
    /* overflow-y: scroll; */
  }

  
</style>
